package com.spider.demo1create;

public class ThreadDemo2 {
    public static void main(String[] args) {
        //目标：掌握多线程的创建方式二：实现Runnable接口来创建
        //3.创建线程任务类的对象代表一个线程任务
        Runnable myRunnable = new MyRunnable();
        //4.创建Thread类对象，构造方法中传递Runnable接口实现类对象
        Thread t = new Thread(myRunnable);
        //5.调用start方法开启多线程
        t.start();
        for (int i = 0; i < 5; i++) {
            System.out.println("主线程输出"+i);
        }
    }
}
//1.定义一个线程任务类实现Runnable接口
class MyRunnable implements Runnable{
    //2.重写run方法，设置线程任务
    @Override
    public void run() {
        for (int i = 0; i < 5; i++) {
            System.out.println("子线程输出"+i);
        }

    }
}